package com.mjh.action;

import java.util.ArrayList;
import org.apache.log4j.Logger;
import com.opensymphony.xwork2.ActionSupport;
import com.mjh.bean.Category;
import com.mjh.manager.CategoryConfigManager;

public class CategoryConfigAction extends ActionSupport{

	private static final long serialVersionUID = -5969814568349114819L;
	
	public static Logger log = Logger.getLogger(CategoryConfigAction.class);
	
	private CategoryConfigManager manager = new CategoryConfigManager();
	
	private ArrayList<Category> categorys;
	
	private String categoryId;
	
	private String categoryName;
	
	public String listCategory(){
		categorys = manager.listCategory();
		return SUCCESS;
	}
	
	public String addCategory(){
		if(categoryName != null){
			manager.addCategory(categoryName);
		}
		return listCategory();
	}

	public String editCategory(){
		if(categoryId !=null && categoryName != null){
			manager.updateCategory(categoryId, categoryName);
		}
		return listCategory();
	}

	public String delCategory(){
		if(categoryId !=null){
			manager.removeCategory(categoryId);
		}
		return listCategory();
	}
	
	public String addSubcategory(){
		if(categoryId !=null && categoryName != null){
			manager.addSubCategory(categoryId, categoryName);
		}
		return listCategory();
	}
	
	public String editSubcategory(){
		if(categoryId !=null && categoryName != null){
			manager.updateCategory(categoryId, categoryName);
		}
		return listCategory();
	}

	public String delSubcategory(){
		if(categoryId !=null){
			manager.removeCategory(categoryId);
		}
		return listCategory();
	}	
	
	public ArrayList<Category> getCategorys() {
		return categorys;
	}

	public void setCategorys(ArrayList<Category> categorys) {
		this.categorys = categorys;
	}

	public String getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(String categoryId) {
		this.categoryId = categoryId;
	}

	public String getCategoryName() {
		return categoryName;
	}

	public void setCategoryName(String categoryName) {
		this.categoryName = categoryName;
	}
}
